layui.use(['table', 'admin', 'form', 'ax', 'upload','layer'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var form = layui.form;
    var upload = layui.upload;
    var layer = layui.layer;
    /**
     * 门店装修表管理
     */
    var Mdzx = {
        tableId: "mdzxTable"
    };

    /**
     * 初始化表格的列
     */
    Mdzx.initColumn = function () {
        return [[
            // {type: 'checkbox'},
            {type: 'numbers', title: '序号', align: "center", width: 45},
            {field: 'btyZxMdzxId', hide: true, title: '主键'},
            {field: 'btyBrandIdView', align: "center", title: '门店名称', width: 300},
            {field: 'mdBianma', align: "center", title: '妖码', width: 90},
            {field: 'mianji', title: '面积', width: 100, align: "center",},
            {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 60}

        ]];
    };

    /**
     * 点击查询按钮
     */
    Mdzx.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        table.reload(Mdzx.tableId, {where: queryData});
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + Mdzx.tableId,
        url: Feng.ctxPath + '/mdzx/list',
        page: true,
        height: "full-98",
        cellMinWidth: 100,
        limit:20,
        totalRow: true,
        cols: Mdzx.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        Mdzx.search();
    });

    // 工具条点击事件
    table.on('tool(' + Mdzx.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if(layEvent==='queren'){
            Mdzx.queren(data);
        }
    });

    Mdzx.queren=function(data){
        var btyZxMdzxId=data.btyZxMdzxId;
        var ids = Feng.getUrlParam("ids");
        var operation = function () {
            $.ajax({
                url: Feng.ctxPath + "/dgdzxChengbenMingxi/mergeMendian",
                cache: false,
                dataType:"json",
                data:  {
                    ids:ids,
                    btyZxMdzxId:btyZxMdzxId
                },
                timeout: 600*1000,//10min
                beforeSend: function () {
                },
                success: function (data) {
                    if (data.code == 200) {
                        Feng.success("更新成功!");
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }else {
                        Feng.error(data.message);
                    }
                },
                error: function (data) {
                    layer.alert('失败！');

                }
            });
        };
        Feng.confirm("确定合并为此门店?", operation);
    };

});
